import { defineStore } from 'pinia'

export { useUserStore } from './modules/userStore'

// 公共store
export const useMainStore = defineStore('main-store', {
  state: () => {
    return {
      theme: localStorage.getItem('theme') === 'dark' ? 'dark' : 'light',
      isAddedRoute: false, // 是否已经添加路由
      pageLoading: false,
      pagination: {
        page: 1,
        pageSize: 10,
        itemCount: 0,
        pageSizes: [5, 10, 20, 50],
        showQuickJumper: true,
        showSizePicker: true,
        prefix: ({ itemCount }) => `共 ${itemCount} 条`,
        displayOrder: ['pages', 'size-picker', 'quick-jumper'],
        simple: document.body.clientWidth < 1280,
      },
    }
  },
  getters: {},
  actions: {
    setIsAddedRoute (val) {
      this.isAddedRoute = val
    },
    setPageLoading (val) {
      this.pageLoading = val
    },
    setPaginationSimple (val) {
      this.pagination.simple = val
    },
    setTheme (val) {
      this.theme = val
      localStorage.setItem('theme', val)
    },
  },
})
